<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ruby Summary: Ruby Study Notes - Best Ruby Guide, Ruby Tutorial</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Ruby Study Notes - Best Ruby Guide, Ruby Tutorial" />
<meta name="keywords" content="free ruby programming guide,ruby guide,free ruby programming course,best ruby guide,ruby tutorials,ruby tutorial,learn ruby,ruby,ruby on rails,ruby rails,ruby learning,ruby tutoring,learning ruby,ruby programming,ruby on rails development,ruby training" />
<meta name="Distribution" content="Global" />
<meta name="author" content="Satish Talim / Original design: Erwin Aligam - ealigam@gmail.com" />
<meta name="copyright" content="Satish Talim 2007 and beyond..." />
<meta name="verify-v1" content="rFu86se+IkbtF+bH8mgJBKwU5HnKaSd8Ghw9umXQOkM=" />
<meta name="robots" content="index,follow" />
<meta http-equiv="Expires" content="0" />
<meta name="revisit-after" content="1 days" />
<link rel="stylesheet" href="/images/NewOrange.css" type="text/css" />
<link rel="icon" type="image/ico" href="/images/favicon.ico" />
<!-- Google +1 button code -->
<link rel="canonical" href="/satishtalim/ruby_summary6.html" />
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>

<!-- Google Analytics code -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-59044-10']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!-- Google Analytics code ends -->
</head>

<body>
<!-- wrap starts here -->
<div id="wrap">

    <div id="header">

        <h1 id="logo">Ruby<span class="orange">Learning.github.io</span></h1>
        <h2 id="slogan">Helping Ruby Programmers become Awesome!</h2>

    </div>

    <div id="menu">
        <ul>
            <li><a href="/" title="Home page for rubylearning.github.io">Home</a></li>
            <li><a href="/satishtalim/tutorial.html" title="Get started Learning Ruby here...">Tutorial</a></li>
            <li><a href="/download/downloads.html" title="Download this tutorial as an eBook">Downloads</a></li>
            <li><a href="/other/testimonials.html" title="People around the world who benefited from this site">Testimonials</a></li>
            <li><a href="/other/certification.html" title="Get certified in Ruby">Certification</a></li>
            <li><a href="/satishtalim/ruby_guide.html" title="Ruby Guide, Mentor">Mentor</a></li>
            <li><a href="https://blog.rubylearning.github.io/" title="Ruby blog of Learning Ruby site">Blog</a></li>
            <li><a href="/satishtalim/tutorial.html" title="Online Ruby Course">Online Course</a></li>
            <li><a href="http://ruby-challenge.rubylearning.github.io/" title="Ruby Programming Challenge for Newbies">Challenge</a></li>
            <li><a href="/satishtalim/about.html" title="Information about Satish Talim">About</a></li>
        </ul>
    </div>

    <!-- content-wrap starts here -->
    <div id="content-wrap">

            <div id="main">
                <!-- google_ad_section_start -->
                <div id="main-inner"><a name="TemplateInfo"></a>
                <h1>Ruby Summary</h1>

                <p class="post-footer align-right">
                  <strong>
                    <a href="/satishtalim/ruby_time_class.html">&lt;Time Class | </a>
                    <a href="/satishtalim/tutorial.html">TOC | </a>
                    <a href="/satishtalim/duck_typing.html">Duck Typing&gt;</a>
                  </strong>
                </p>

                <ol>
                  <li>Ruby gives you three levels of protection:<ul><li><strong>public</strong> - methods can be called by everyone. A class's instance methods are public by default.</li><li><strong>protected</strong> - methods can be invoked only by objects of the defining class and its subclasses.</li><li><strong>private</strong> - methods cannot be called with an explicit receiver - the receiver is always <strong>self</strong>. This means that private methods can be called only in the context of the current object. The initialize method is always private.</li></ul></li>
                  <li>Access control is determined dynamically, as the program runs, not statically. You will get an access violation only when the code attempts to execute the restricted method.</li>
                  <li>Top-level methods are private instance methods of the <strong>Object</strong> class.</li>
                  <li>attr_reader is reader only; attr_writer is writer only and attr_accessor is both reader and writer.</li>
                  <li>An exception is a special kind of object, an instance of the class <strong>Exception</strong> or a descendant of that class.</li>
                  <li>The <strong>raise</strong> method is from the <strong>Kernel</strong> module. By default, <strong>raise</strong> creates an exception of the <strong>RuntimeError</strong> class. To raise an exception of a specific class, you can pass in the class name as an argument to <strong>raise</strong>.</li>
                  <li>To do exception handling, we enclose the code that could raise an exception in a <strong>begin-end</strong> block and use one or more <strong>rescue</strong> clauses to tell Ruby the types of exceptions we want to handle.</li>
                  <li>It is to be noted that the body of a method definition is an implicit <strong>begin-end</strong> block; the begin is omitted, and the entire body of the method is subject to exception handling, ending with the end of the method.</li>
                  <li>If you write a <strong>rescue</strong> clause with no parameter list, the parameter defaults to <strong>StandardError</strong>.</li>
                  <li>If you need the guarantee that some processing is done at the end of a block of code, regardless of whether an exception was raised then the <strong>ensure</strong> clause can be used. <strong>ensure</strong> goes after the last <strong>rescue</strong> clause and contains a chunk of code that will always be executed as the block terminates. The <strong>ensure</strong> block will always run.</li>
                  <li>By default, the inspect message, which can be sent to any object, formats the object's ID and instance variables. It returns a string containing a human-readable representation of object. If not overridden, uses the to_s method to generate the string.</li>
                  <li>When writing rescue clauses, ensure that you rescue from subclassed Exceptions first and then more general Exceptions, otherwise you will not rescue the more specific error. For example, you would rescue based on NoMethodError before NameError, and those before the more general (superclass) StandardError.</li>
                  <li>The <strong>Time</strong> class contains Ruby's interface to the set of time libraries written in C.</li>
                  <li>Time zero for Ruby is the first second GMT of January 1, 1970.</li>
                  <li>Ruby's <strong>DateTime</strong> class is superior to <strong>Time</strong> for astronomical and historical applications, but you can use <strong>Time</strong> for most everyday programs.</li>
                </ol>

                <p style="background-color: #FAFAFA; padding: 5px; margin-top: 20px; font-size: 65%;"><strong>Note</strong>: The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. I have made extensive references to information, related to Ruby, available in the public domain (wikis and the blogs, articles of various <span style="font-weight: bold;" title="Click Gurus on the menu above">Ruby Gurus</span>), my acknowledgment and thanks to all of them. Much of the material on <a href="/">rubylearning.github.io</a> and in the course at <a href="http://rubylearning.org/">rubylearning.org</a> is drawn <strong>primarily</strong> from the <strong>Programming Ruby book</strong>, available from <a href="http://pragprog.com/book/ruby3/programming-ruby-1-9-2-0">The Pragmatic Bookshelf</a>.</p>

                <!-- google_ad_section_end -->
                <p class="post-footer align-right">
                  <strong>
                    <a href="/satishtalim/ruby_time_class.html">&lt;Time Class | </a>
                    <a href="/satishtalim/tutorial.html">TOC | </a>
                    <a href="/satishtalim/duck_typing.html">Duck Typing&gt;</a>
                  </strong>
                </p>

            </div>
            <!-- main inner ends here -->
        </div>

            <div id="rightbar">

            </div>

    <!-- content-wrap ends here -->
    </div>

<!-- wrap ends here -->
</div>

<!-- footer starts here -->
<div id="footer">
    <!-- CHANGE THE FOOTER -->
    <p>&copy; 2006-2021 <strong>rubylearning.github.io - A Ruby Tutorial</strong>&nbsp;&nbsp;Page Updated: 5th Jan. 2021 | Design: <a href="mailto:ealigam@gmail.com">Erwin Aligam</a> | Valid: <a href="http://validator.w3.org/check/referer">XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/">Home</a> | <a href="/privacy.html">Privacy</a> | <a href="/sitemap.html">Sitemap</a></p>
</div>
<!-- footer ends here -->
</body>
</html>
